<template>
    <div class="home">
        <router-view :user="user" :account="account" @setLogin="setLogin"></router-view>
        <van-tabbar v-model="active" active-color="#1ba784">
            <van-tabbar-item to="/shopping" icon="shop-o">首页</van-tabbar-item>
            <van-tabbar-item to="/shoppingcart" icon="shopping-cart-o">购物车</van-tabbar-item>
            <van-tabbar-item to="/my" icon="user-o">我的</van-tabbar-item>
        </van-tabbar>
    </div>
</template>

<script>
export default {
    props: ["user", "account", "ssetLogin"],
    name: "HomeView",
    data() {
        return {
            active: 0,
        };
    },
    methods: {
        setLogin({ user, account, active }) {
            this.$emit("ssetLogin", { user, account });
            this.active = active;
        },
    },
    beforeRouteEnter(to, from, next) {
        next((vm) => {
            if (vm.$route.path == "/shopping") {
                vm.active = 0;
            }
            if (vm.$route.path == "/shoppingcart") {
                vm.active = 1;
            }
            if (vm.$route.path == "/my") {
                vm.active = 2;
            }
        });
    },
};
</script>
